home *** CD-ROM | disk | FTP | other *** search
/ Spidla DivX / DivX.bin / FLAC 1.1.0 / include / FLAC++ / encoder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-01  |  13.3 KB  |  352 lines

  1. /* libFLAC++ - Free Lossless Audio Codec library
  2.  * Copyright (C) 2002,2003  Josh Coalson
  3.  *
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Library General Public
  6.  * License as published by the Free Software Foundation; either
  7.  * version 2 of the License, or (at your option) any later version.
  8.  *
  9.  * This library is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  * Library General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Library General Public
  15.  * License along with this library; if not, write to the
  16.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.  * Boston, MA  02111-1307, USA.
  18.  */
  19.  
  20. #ifndef FLACPP__ENCODER_H
  21. #define FLACPP__ENCODER_H
  22.  
  23. #include "export.h"
  24.  
  25. #include "FLAC/file_encoder.h"
  26. #include "FLAC/seekable_stream_encoder.h"
  27. #include "FLAC/stream_encoder.h"
  28. #include "decoder.h"
  29.  
  30.  
  31. /** \file include/FLAC++/encoder.h
  32.  *
  33.  *  \brief
  34.  *  This module contains the classes which implement the various
  35.  *  encoders.
  36.  *
  37.  *  See the detailed documentation in the
  38.  *  \link flacpp_encoder encoder \endlink module.
  39.  */
  40.  
  41. /** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
  42.  *  \ingroup flacpp
  43.  *
  44.  *  \brief
  45.  *  This module describes the three encoder layers provided by libFLAC++.
  46.  *
  47.  * The libFLAC++ encoder classes are object wrappers around their
  48.  * counterparts in libFLAC.  All three encoding layers available in
  49.  * libFLAC are also provided here.  The interface is very similar;
  50.  * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
  51.  *
  52.  * The only real difference here is that instead of passing in C function
  53.  * pointers for callbacks, you inherit from the encoder class and provide
  54.  * implementations for the callbacks in the derived class; because of this
  55.  * there is no need for a 'client_data' property.
  56.  */
  57.  
  58. namespace FLAC {
  59.     namespace Encoder {
  60.  
  61.         // ============================================================
  62.         //
  63.         //  Equivalent: FLAC__StreamEncoder
  64.         //
  65.         // ============================================================
  66.  
  67.         /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
  68.          *  \ingroup flacpp_encoder
  69.          *
  70.          *  \brief
  71.          *  This class wraps the ::FLAC__StreamEncoder.
  72.          *
  73.          * See the \link flac_stream_encoder libFLAC stream encoder module \endlink.
  74.          *
  75.          * \{
  76.          */
  77.  
  78.         /** This class wraps the ::FLAC__StreamEncoder.
  79.          */
  80.         class FLACPP_API Stream {
  81.         public:
  82.             class FLACPP_API State {
  83.             public:
  84.                 inline State(::FLAC__StreamEncoderState state): state_(state) { }
  85.                 inline operator ::FLAC__StreamEncoderState() const { return state_; }
  86.                 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
  87.                 const char *resolved_as_cstring(const Stream &) const;
  88.             protected:
  89.                 ::FLAC__StreamEncoderState state_;
  90.             };
  91.  
  92.             Stream();
  93.             virtual ~Stream();
  94.  
  95.             bool is_valid() const;
  96.             inline operator bool() const { return is_valid(); }
  97.  
  98.             bool set_verify(bool value);
  99.             bool set_streamable_subset(bool value);
  100.             bool set_do_mid_side_stereo(bool value);
  101.             bool set_loose_mid_side_stereo(bool value);
  102.             bool set_channels(unsigned value);
  103.             bool set_bits_per_sample(unsigned value);
  104.             bool set_sample_rate(unsigned value);
  105.             bool set_blocksize(unsigned value);
  106.             bool set_max_lpc_order(unsigned value);
  107.             bool set_qlp_coeff_precision(unsigned value);
  108.             bool set_do_qlp_coeff_prec_search(bool value);
  109.             bool set_do_escape_coding(bool value);
  110.             bool set_do_exhaustive_model_search(bool value);
  111.             bool set_min_residual_partition_order(unsigned value);
  112.             bool set_max_residual_partition_order(unsigned value);
  113.             bool set_rice_parameter_search_dist(unsigned value);
  114.             bool set_total_samples_estimate(FLAC__uint64 value);
  115.             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
  116.  
  117.             State    get_state() const;
  118.             Decoder::Stream::State get_verify_decoder_state() const;
  119.             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  120.             bool     get_verify() const;
  121.             bool     get_streamable_subset() const;
  122.             bool     get_do_mid_side_stereo() const;
  123.             bool     get_loose_mid_side_stereo() const;
  124.             unsigned get_channels() const;
  125.             unsigned get_bits_per_sample() const;
  126.             unsigned get_sample_rate() const;
  127.             unsigned get_blocksize() const;
  128.             unsigned get_max_lpc_order() const;
  129.             unsigned get_qlp_coeff_precision() const;
  130.             bool     get_do_qlp_coeff_prec_search() const;
  131.             bool     get_do_escape_coding() const;
  132.             bool     get_do_exhaustive_model_search() const;
  133.             unsigned get_min_residual_partition_order() const;
  134.             unsigned get_max_residual_partition_order() const;
  135.             unsigned get_rice_parameter_search_dist() const;
  136.             FLAC__uint64 get_total_samples_estimate() const;
  137.  
  138.             State init();
  139.  
  140.             void finish();
  141.  
  142.             bool process(const FLAC__int32 * const buffer[], unsigned samples);
  143.             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
  144.         protected:
  145.             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
  146.             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
  147.  
  148.             ::FLAC__StreamEncoder *encoder_;
  149.         private:
  150.             static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
  151.             static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
  152.  
  153.             // Private and undefined so you can't use them:
  154.             Stream(const Stream &);
  155.             void operator=(const Stream &);
  156.         };
  157.  
  158.         /* \} */
  159.  
  160.         /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
  161.          *  \ingroup flacpp_encoder
  162.          *
  163.          *  \brief
  164.          *  This class wraps the ::FLAC__SeekableStreamEncoder.
  165.          *
  166.          * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
  167.          *
  168.          * \{
  169.          */
  170.  
  171.         /** This class wraps the ::FLAC__SeekableStreamEncoder.
  172.          */
  173.         class FLACPP_API SeekableStream {
  174.         public:
  175.             class FLACPP_API State {
  176.             public:
  177.                 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
  178.                 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
  179.                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
  180.                 const char *resolved_as_cstring(const SeekableStream &) const;
  181.             protected:
  182.                 ::FLAC__SeekableStreamEncoderState state_;
  183.             };
  184.  
  185.             SeekableStream();
  186.             virtual ~SeekableStream();
  187.  
  188.             bool is_valid() const;
  189.             inline operator bool() const { return is_valid(); }
  190.  
  191.             bool set_verify(bool value);
  192.             bool set_streamable_subset(bool value);
  193.             bool set_do_mid_side_stereo(bool value);
  194.             bool set_loose_mid_side_stereo(bool value);
  195.             bool set_channels(unsigned value);
  196.             bool set_bits_per_sample(unsigned value);
  197.             bool set_sample_rate(unsigned value);
  198.             bool set_blocksize(unsigned value);
  199.             bool set_max_lpc_order(unsigned value);
  200.             bool set_qlp_coeff_precision(unsigned value);
  201.             bool set_do_qlp_coeff_prec_search(bool value);
  202.             bool set_do_escape_coding(bool value);
  203.             bool set_do_exhaustive_model_search(bool value);
  204.             bool set_min_residual_partition_order(unsigned value);
  205.             bool set_max_residual_partition_order(unsigned value);
  206.             bool set_rice_parameter_search_dist(unsigned value);
  207.             bool set_total_samples_estimate(FLAC__uint64 value);
  208.             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
  209.  
  210.             State    get_state() const;
  211.             Stream::State get_stream_encoder_state() const;
  212.             Decoder::Stream::State get_verify_decoder_state() const;
  213.             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  214.             bool     get_verify() const;
  215.             bool     get_streamable_subset() const;
  216.             bool     get_do_mid_side_stereo() const;
  217.             bool     get_loose_mid_side_stereo() const;
  218.             unsigned get_channels() const;
  219.             unsigned get_bits_per_sample() const;
  220.             unsigned get_sample_rate() const;
  221.             unsigned get_blocksize() const;
  222.             unsigned get_max_lpc_order() const;
  223.             unsigned get_qlp_coeff_precision() const;
  224.             bool     get_do_qlp_coeff_prec_search() const;
  225.             bool     get_do_escape_coding() const;
  226.             bool     get_do_exhaustive_model_search() const;
  227.             unsigned get_min_residual_partition_order() const;
  228.             unsigned get_max_residual_partition_order() const;
  229.             unsigned get_rice_parameter_search_dist() const;
  230.             FLAC__uint64 get_total_samples_estimate() const;
  231.  
  232.             State init();
  233.  
  234.             void finish();
  235.  
  236.             bool process(const FLAC__int32 * const buffer[], unsigned samples);
  237.             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
  238.         protected:
  239.             virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
  240.             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
  241.  
  242.             ::FLAC__SeekableStreamEncoder *encoder_;
  243.         private:
  244.             static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  245.             static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
  246.  
  247.             // Private and undefined so you can't use them:
  248.             SeekableStream(const SeekableStream &);
  249.             void operator=(const SeekableStream &);
  250.         };
  251.  
  252.         /* \} */
  253.  
  254.         /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
  255.          *  \ingroup flacpp_encoder
  256.          *
  257.          *  \brief
  258.          *  This class wraps the ::FLAC__FileEncoder.
  259.          *
  260.          * See the \link flac_file_encoder libFLAC file encoder module \endlink.
  261.          *
  262.          * \{
  263.          */
  264.  
  265.         /** This class wraps the ::FLAC__FileEncoder.
  266.          */
  267.         class FLACPP_API File {
  268.         public:
  269.             class FLACPP_API State {
  270.             public:
  271.                 inline State(::FLAC__FileEncoderState state): state_(state) { }
  272.                 inline operator ::FLAC__FileEncoderState() const { return state_; }
  273.                 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
  274.                 const char *resolved_as_cstring(const File &) const;
  275.             protected:
  276.                 ::FLAC__FileEncoderState state_;
  277.             };
  278.  
  279.             File();
  280.             virtual ~File();
  281.  
  282.             bool is_valid() const;
  283.             inline operator bool() const { return is_valid(); }
  284.  
  285.             bool set_verify(bool value);
  286.             bool set_streamable_subset(bool value);
  287.             bool set_do_mid_side_stereo(bool value);
  288.             bool set_loose_mid_side_stereo(bool value);
  289.             bool set_channels(unsigned value);
  290.             bool set_bits_per_sample(unsigned value);
  291.             bool set_sample_rate(unsigned value);
  292.             bool set_blocksize(unsigned value);
  293.             bool set_max_lpc_order(unsigned value);
  294.             bool set_qlp_coeff_precision(unsigned value);
  295.             bool set_do_qlp_coeff_prec_search(bool value);
  296.             bool set_do_escape_coding(bool value);
  297.             bool set_do_exhaustive_model_search(bool value);
  298.             bool set_min_residual_partition_order(unsigned value);
  299.             bool set_max_residual_partition_order(unsigned value);
  300.             bool set_rice_parameter_search_dist(unsigned value);
  301.             bool set_total_samples_estimate(FLAC__uint64 value);
  302.             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
  303.             bool set_filename(const char *value);
  304.  
  305.             State    get_state() const;
  306.             SeekableStream::State get_seekable_stream_encoder_state() const;
  307.             Stream::State get_stream_encoder_state() const;
  308.             Decoder::Stream::State get_verify_decoder_state() const;
  309.             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  310.             bool     get_verify() const;
  311.             bool     get_streamable_subset() const;
  312.             bool     get_do_mid_side_stereo() const;
  313.             bool     get_loose_mid_side_stereo() const;
  314.             unsigned get_channels() const;
  315.             unsigned get_bits_per_sample() const;
  316.             unsigned get_sample_rate() const;
  317.             unsigned get_blocksize() const;
  318.             unsigned get_max_lpc_order() const;
  319.             unsigned get_qlp_coeff_precision() const;
  320.             bool     get_do_qlp_coeff_prec_search() const;
  321.             bool     get_do_escape_coding() const;
  322.             bool     get_do_exhaustive_model_search() const;
  323.             unsigned get_min_residual_partition_order() const;
  324.             unsigned get_max_residual_partition_order() const;
  325.             unsigned get_rice_parameter_search_dist() const;
  326.             FLAC__uint64 get_total_samples_estimate() const;
  327.  
  328.             State init();
  329.  
  330.             void finish();
  331.  
  332.             bool process(const FLAC__int32 * const buffer[], unsigned samples);
  333.             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
  334.         protected:
  335.             virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
  336.  
  337.             ::FLAC__FileEncoder *encoder_;
  338.         private:
  339.             static void progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
  340.  
  341.             // Private and undefined so you can't use them:
  342.             File(const Stream &);
  343.             void operator=(const Stream &);
  344.         };
  345.  
  346.         /* \} */
  347.  
  348.     };
  349. };
  350.  
  351. #endif
  352.